package edu.ncu.dao;

import edu.ncu.entity.Photo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PhotoDao {
    @Select("select * from photo;")
    List<Photo> findAll();

    /**
     * 根据用户id查找出所有照片（查找某用户的相册）
     * @param userId
     * @return
     */
    @Select("select * from photo where userId = #{userId};")
    List<Photo> findByUserId(int userId);

    /**
     * 保存photo到数据库中
     * @param photo
     * @return 返回值是新增数据的ID
     */
    @Insert("insert into photo (userId, photoName, likeNum, commentNum) " +
            "values (#{userId}, #{photoName}, #{likeNum}, #{commentNum});")
    int savePhoto(Photo photo);

    /**
     * 删除照片
     * @param photoId
     * @return
     */
    @Delete("delete from photo where photoId = #{photoId};")
    int deletePhoto(int photoId);

    @Select("select * from photo where photoId = #{photoId};")
    Photo findPhotoById(int photoId);

}
